//
//  CycleBaseScrollView.m
//  CycleBaseControl
//
//  Created by ddy on 2018/8/14.
//  Copyright © 2018年 cycle. All rights reserved.
//

#import "CycleBaseScrollView.h"

@implementation CycleBaseScrollView
//如果初始化是 [[CycleBaseScrollView alloc]initWithFrame:self.view.bounds];则不会走下面的init
//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        [self cycle_init_scrollView];
//    }
//    return self;
//}
-(void)awakeFromNib{
    [super awakeFromNib];
    [self cycle_init_scrollView];
}
//这样写三个都走
/*
 [CycleBaseScrollView new];
 [[CycleBaseScrollView alloc]init];
 [[CycleBaseScrollView alloc]initWithFrame:self.view.bounds];
 */
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self cycle_init_scrollView];
    }
    return self;
}

/**
 * 初始化
 */
- (void)cycle_init_scrollView{
    if (@available(iOS 11.0, *)) {
        self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
        //此句代码在 某个用到该类的控制器写，不让控制器调整scrollView的Insets，iOS11后上面代码替换了下面的代码
             //   self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
}
/*
 UIScrollViewContentInsetAdjustmentAutomatic：如果scrollview在一个automaticallyAdjustsScrollViewContentInset = YES的controller上，并且这个Controller包含在一个navigation controller中，这种情况下会设置在top & bottom上 adjustedContentInset = safeAreaInset + contentInset不管是否滚动。其他情况下与UIScrollViewContentInsetAdjustmentScrollableAxes相同
 
 UIScrollViewContentInsetAdjustmentScrollableAxes: 在可滚动方向上adjustedContentInset = safeAreaInset + contentInset，在不可滚动方向上adjustedContentInset = contentInset；依赖于scrollEnabled和alwaysBounceHorizontal / vertical = YES，scrollEnabled默认为yes，所以大多数情况下，计算方式还是adjustedContentInset = safeAreaInset + contentInset；
 
 UIScrollViewContentInsetAdjustmentNever: adjustedContentInset = contentInset
 
 UIScrollViewContentInsetAdjustmentAlways: adjustedContentInset = safeAreaInset + contentInset
 
 当contentInsetAdjustmentBehavior设置为UIScrollViewContentInsetAdjustmentNever的时候，adjustContentInset值不受SafeAreaInset值的影响。
 
 */
@end
